package com.ifar.audiosdk

import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkRequest
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.Utils
import com.ifar.audiosdk.broadcast.NetworkCallbackImpl
import com.tencent.bugly.crashreport.CrashReport
import kotlin.properties.Delegates

class App : IfarBaseApp() {

    companion object {
        var CONTEXT: Context by Delegates.notNull()
        var instance: App by Delegates.notNull()
    }

    override fun onCreate() {
        super.onCreate()

        CONTEXT = applicationContext
        instance = this

        Utils.init(this)
        initARouter()
        initNetChangeCallBack()
        CrashReport.initCrashReport(applicationContext, "90159397fe", false);
    }

    private fun initARouter() {
        //ARouter调试配置
        ARouter.openLog()
        ARouter.openDebug()
        //ARouter加载
        ARouter.init(this)
    }

    /**初始化网络监听*/
    private fun initNetChangeCallBack() {
        val networkCallback = NetworkCallbackImpl()
        val builder = NetworkRequest.Builder()
        val request = builder.build()
        val connMgr = getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager
        connMgr.registerNetworkCallback(request, networkCallback)
    }

}